package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.VisitHistory;
import com.example.mapper.VisitHistoryMapper;
import com.example.service.VisitHistoryService;
import com.example.vo.VisitHistoryVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class VisitHistoryServiceImpl extends ServiceImpl<VisitHistoryMapper, VisitHistory> implements VisitHistoryService {

    @Resource
    private VisitHistoryMapper visitHistoryMapper;

    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    @Override
    public List<VisitHistoryVO> findByLimit(int num) {
        return visitHistoryMapper.selectByLimit(num);
    }

    @Override
    public Integer falseDelete(int id) {
        return visitHistoryMapper.falseDelete(id);
    }

    @Override
    public List<VisitHistory> queryVisitLocation(int id) {
        return visitHistoryMapper.findVideoLocation(id);
    }

    @Override
    public Page<VisitHistory> queryPage(int page , int size) {

        Page<VisitHistory> visitHistoryPage=new Page<>(page,size);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("delete_flag", 1);
        queryWrapper.orderByDesc("create_date");
        Page<VisitHistory> page1 = visitHistoryMapper.selectPage(visitHistoryPage, queryWrapper);
        return page1;

    }
    public Page<VisitHistory> queryPage1(int page , int size) {

        Page<VisitHistory> visitHistoryPage=new Page<>(page,size);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.orderByDesc("create_date");
        Page<VisitHistory> page1 = visitHistoryMapper.selectPage(visitHistoryPage, queryWrapper);
        return page1;

    }

    @Override
    public Integer deleteAll() {
       return   visitHistoryMapper.deleteAll();
    }

/*    @Override
    public List<VisitHistoryVO> autoIncrease(VisitHistoryVO visitHistoryVO) {
        List<VisitHistoryVO> visitHistoriesVO = visitHistoryMapper.autoIncrease(visitHistoryVO);
        return visitHistoriesVO;
    }*/

}
